<template>
  <view>
    <!-- 选择收货地址盒子 -->
    <view class="address-choose-box" v-if="JSON.stringify(address)==='{}'">
      <button type="primary" size="mini" class="btnChoose" @click="chooseAddress">请选择收货地址+</button>
    </view>
    <!-- 收货人信息盒子 -->
    <view class="address-info-box" v-else @click="chooseAddress">
      <view class="address-top">
        <view class="address-left">
          收货人：{{address.userName}}
        </view>
        <view class="addess-right">
          电话：{{address.telNumber}}
          <uni-icons type="right" size="16"></uni-icons>
        </view>
      </view>
      <view class="address-bottom" @click="abc">
        收货地址：{{addstr}}
      </view>
    </view>
    <image src="/static/border.png" class="address-border"></image>
  </view>
</template>

<script>
  import {mapState,mapMutations,mapGetters} from 'vuex'
  export default {
    name:"my-address",
    computed:{
      ...mapState('m_user',['address']),
      ...mapGetters('m_user',['addstr'])
    },
    methods:{
      ...mapMutations('m_user',['updateAddress']),
      async chooseAddress(){
        const [err,succ]=await uni.chooseAddress().catch(err=>err)
        if(err===null&&succ.errMsg==='chooseAddress:ok'){
          this.updateAddress(succ)
        }
      }
    }
  }
</script>

<style lang="scss">
.address-choose-box{
  height: 90px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.address-info-box{
  font-size: 13px;
  padding: 10px 5px;
  .address-bottom,
  .address-top{
    margin: 10px 0;
  }
  .address-top{
    display: flex;
    justify-content: space-between;
  }
}

.address-border{
  display: block;
  width: 100%;
  height: 5px;
}
</style>
